#include <stdio.h>
/*
* I_2.c
*
*  Created on: April, 23, 2009
*      Author: yimingliu@fudan.edu.cn
*/

int funI_2_fun(char *source, char *target)
{
	FILE *fs,*ft;
	char ch;
	if((fs=fopen(source,"r"))==NULL)
		return 0;
	if((ft=fopen(target,"w"))==NULL)
		return 0;
	printf("\nThe data in file: \n");
	ch=fgetc(fs);
	while(!feof(fs))
	{
		putchar(ch);
		fputc(ch,ft);
		ch=fgetc(fs);
	}
	fclose(fs);
	fclose(ft);
	printf("\n\n");
	return 1;
}

void funI_2()
{
	char sfname[20]="myfile1",tfname[20]="myfile2";
	FILE *myf;
	int i;
	char c;
	myf=fopen(sfname,"w");
	printf("\nThe original data: \n");
	for(i=1;i<30;i++)
	{
		c='A'+rand()%25;
		fprintf(myf,"%c",c);
		printf("%c",c);
	}
	fclose(myf);
	printf("\n\n");
	if(funI_2_fun(sfname,tfname))
		printf("Succeed!");
	else
		printf("Fail!");
}